package com.woniu.payback_font.service.impl;



import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.payback_font.entity.Load;
import com.woniu.payback_font.entity.LoanApplication;
import com.woniu.payback_font.entity.Repayment;
import com.woniu.payback_font.mapper.LoadMapper;
import com.woniu.payback_font.mapper.LoanApplicationMapper;
import com.woniu.payback_font.mapper.LoanMapper;
import com.woniu.payback_font.service.LoadService;
import com.woniu.payback_font.vo.LoanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoadServiceImpl implements LoadService {
    @Autowired
    private LoanApplicationMapper loanApplicationMapper;

    @Autowired
    private LoanMapper loanMapper;

    @Autowired
    private LoadMapper loadMapper;

    @Override
    public List<LoanApplication> findLoanApplications() {
        return loanApplicationMapper.selectAll()/*loanApplicationMapper.dynamicSearch()*/;
    }

    @Override
    public PageInfo<LoanApplication> dynamicPageSeach(Integer pageNum,
                                                      Integer pageSize,
                                                      String laName,
                                                      String laMobile,
                                                      String laIdcard,
                                                      String laInvestorName,
                                                      Integer laLoadApplicationStatus) {
        PageHelper.startPage(pageNum,pageSize);
        List<LoanApplication> list = loanApplicationMapper.dynamicSearch(laName, laMobile, laIdcard, laInvestorName, laLoadApplicationStatus);
        return new PageInfo<>(list);
    }

    @Override
    public int addLoan(LoanVo loanVo) {
        return loanMapper.insert(loanVo);
    }

    @Override
    public int addfalseLoan(LoanVo loanVo) {
        return loanMapper.insert(loanVo);
    }

    /**
     * 多条件查询 借款信息查询
     * @param lName 借款人名称（模糊查询）
     * @param lMobile 借款人手机号
     * @param lReceiptNo 借据号
     * @param lProductName 借款产品
     * @param lInvestorName 资方名称
     * @return
     */
    @Override
    public PageInfo<Load> findByPrimarydata(Integer pageNum, Integer pageSize,String lName, String lMobile, String lReceiptNo, String lProductName, String lInvestorName) {
        PageHelper.startPage(pageNum,pageSize);
        List<Load> list = loadMapper.findByPrimarydata(lName, lMobile, lReceiptNo, lProductName, lInvestorName);
        return new PageInfo<>(list);
    }


    /**
     *  借款详情查询接口（显示单条数据）
     * @return
     */
    @Override
    public Load findOne(Integer lId) {
        return loadMapper.findOne(lId);
    }

    @Override
    public PageInfo<Load> showUserLoan(Integer pageNum, Integer pageSize, String aUid) {
        PageHelper.startPage(pageNum,pageSize);
        List<Load> list = loadMapper.showUserLoan(aUid);
        return new PageInfo<>(list);
    }


}
